<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head th:replace="common/header::common_head"></head>
<link rel="stylesheet" href="../bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
<title>库存调拨单</title>
<style type="text/css">
</style>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <div th:replace="common/LeftCommon::common_top_left"></div>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <div>
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>
                    库存调拨单
                </h1>
                <ol class="breadcrumb">
                    <li><a href="/index"><i class="fa fa-dashboard"></i> 首页</a></li>
                    <li><a href="#">仓库</a></li>
                    <li class="active">库存调拨单</li>
                </ol>
            </section>
            <!-- Main content -->
            <section class="content">
                <div class="col-md-3">
                    <!--左上方导航-->
                    <div class="box box-primary">
                        <div class="box-header">
                            <ul class="nav nav-pills">
                                <li role="presentation" class="active"><a href="#">默认</a></li>
                                <li role="presentation"><a href="#">草稿</a></li>
                                <li role="presentation"><a href="#">已盘点</a></li>
                                <li role="presentation"><a href="#">已撤销</a></li>
                            </ul>
                        </div>
                        <form>
                            <div class="box-body">
                                <!-- Date range -->
                                <div class="form-group">
                                    <!-- select -->
                                    <div class="form-group">
                                        <label>制单人</label>
                                        <select class="form-control">
                                            <option>仓库1</option>
                                            <option>仓库2</option>
                                        </select>
                                    </div>

                                    <div class="form-group">
                                        <label>调出仓库</label>
                                        <select class="form-control">
                                            <option>仓库1</option>
                                            <option>仓库2</option>
                                        </select>
                                    </div>

                                    <div class="form-group">
                                        <label>调入参数</label>
                                        <select class="form-control">
                                            <option>仓库1</option>
                                            <option>仓库2</option>
                                        </select>
                                    </div>

                                    <!--日期选择-->
                                    <div class="form-group">
                                        <label>日期</label>
                                        <div class="input-group">
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="form-control pull-right" id="reservation">
                                        </div>
                                    </div>
                                    <!-- /.input group -->
                                    <label>单号</label>
                                    <div class="input-group input-group-sm">
                                        <input type="text" class="form-control">
                                        <span class="input-group-btn">
                                             <button type="button" class="btn btn-info btn-flat">查询</button>
                                            </span>
                                    </div>
                                    <!-- /.input group -->
                                </div>
                                <!-- /.form group -->
                            </div>
                            <!-- /.box-body -->
                        </form>

                    </div>
                    <!--左下方表格-->
                    <div class="box">
                        <div class="box-header with-border">
                        </div>
                            <div class="box-body">
                                <table class="table table-bordered" id="leftTable">
                                    <thead>
                                    <tr>
                                        <th>订单号</th>
                                        <th>客户名称</th>
                                        <th>调入仓库</th>
                                        <th>日期</th>
                                        <th>状态</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr th:each="orderDTO,orderStart : ${orderDTOList}">
                                        <td th:text="${orderDTO.orderId}"></td>
                                        <td th:text="${orderDTO.outStoreName}"></td>
                                        <td th:text="${orderDTO.inStoreName}"></td>
                                        <td th:text="${#dates.format(orderDTO.createTime, 'yyyy-MM-dd  HH:mm:ss')}"></td>
                                        <td th:switch="${orderDTO.orderStatus}">
                                            <span th:case= 0 class="label label-info" th:value="0">草稿</span>
                                            <span th:case= 1 class="label label-warning" th:value="1">等待确认</span>
                                            <span th:case= 2 class="label label-primary" th:value="2">正在调拨</span>
                                            <span th:case= 3 class="label label-success" th:value="3">调拨成功</span>
                                            <span th:case= 4 class="label label-danger" th:value="4">调拨失败</span>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                    </div>
                    <!-- /.box -->
                </div>
                <div class="col-md-9">
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title" >调拨单 </h3>
                            -
                            <span class="box-title" id="orderIdH"></span>
                            <button type="submit" class="btn btn-primary " id="addRequisition"style="float:right">新增调拨单</button>
                        </div>
                        <div class="box-body ">
                            <div class="row" id="goodsSelectD">
                                <div class="col-md-6 col-md-offset-3">
                                    <div class="form-group">
                                        <label>请选择你要调拨的商品</label>
                                        <select class="form-control select2" style="width: 100%;" id="goodsOption" >
                                            <option style='display: none'></option>
                                            <option th:each="option:${goodsOption}" th:text="${option.name}" th:value="${option.barCode}"></option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="row" id ="remarksD" style="display:none;" >
                                <div class="col-md-6 col-md-offset-3">
                                    <div class="form-group">
                                        <label>备注</label>
                                        <input type="text" id="remarks" class="form-control" placeholder="备注 ..."  disabled>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                               <div class="col-md-4 col-xs-6">
                                   <label>调出仓库</label>
                                   <input id ="outStore" type="text" disabled>
                               </div>
                                <div class="col-md-4 col-xs-6">
                                    <label>调入仓库</label>
                                    <input id ="inStore" type="text" disabled >
                                </div>
                                <div class="col-md-4 col-xs-6">
                                    <label>日期</label>
                                    <input id="time" type="text" disabled>
                                </div>
                            </div>
                            <table id="mainTable" class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>商品</th>
                                    <th>货号</th>
                                    <th>条码</th>
                                    <th>颜色</th>
                                    <th>尺码</th>
                                    <th>调拨数量</th>
                                    <th>单价</th>
                                    <th>金额</th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                            </div>
                        <!-- /.box-body -->
                        <div class="box-footer">
                            <button type="submit" id="submitForm" class="btn btn-primary">确认发出调拨请求</button>
                            <button type="submit" id="submitDraft" class="btn btn-primary">存为草稿</button>
                            <button type="submit" id="determine" class="btn btn-primary" style="display:none;">确定调拨</button>
                            <button type="submit" id="finish" class="btn btn-success" style="display:none;">完成调拨</button>
                            <button type="submit" id="close" class="btn btn-danger" style="display:none;" >取消调拨</button>
                        </div>
                    </div>
                    <!-- /.box -->
                </div>
            </section>
            <!-- /.content -->
        </div>
    </div>
    <!-- /.content-wrapper -->
    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>Version</b> 2.4.0
        </div>
        <strong>Copyright &copy; 2014-2016 <a href="https://adminlte.io">Almsaeed Studio</a>.</strong> All rights
        reserved.
    </footer>

    <!-- Control Sidebar -->
    <aside class="control-sidebar control-sidebar-dark">
        <!-- Create the tabs -->
        <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
            <li><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
            <li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
        </ul>
        <!-- Tab panes -->
        <div class="tab-content">
            <!-- Home tab content -->
            <div class="tab-pane" id="control-sidebar-home-tab">
                <h3 class="control-sidebar-heading">Recent Activity</h3>
                <ul class="control-sidebar-menu">
                    <li>
                        <a href="javascript:void(0)">
                            <i class="menu-icon fa fa-birthday-cake bg-red"></i>

                            <div class="menu-info">
                                <h4 class="control-sidebar-subheading">Langdon's Birthday</h4>

                                <p>Will be 23 on April 24th</p>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <i class="menu-icon fa fa-user bg-yellow"></i>

                            <div class="menu-info">
                                <h4 class="control-sidebar-subheading">Frodo Updated His Profile</h4>

                                <p>New phone +1(800)555-1234</p>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <i class="menu-icon fa fa-envelope-o bg-light-blue"></i>

                            <div class="menu-info">
                                <h4 class="control-sidebar-subheading">Nora Joined Mailing List</h4>

                                <p>nora@example.com</p>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <i class="menu-icon fa fa-file-code-o bg-green"></i>

                            <div class="menu-info">
                                <h4 class="control-sidebar-subheading">Cron Job 254 Executed</h4>

                                <p>Execution time 5 seconds</p>
                            </div>
                        </a>
                    </li>
                </ul>
                <!-- /.control-sidebar-menu -->

                <h3 class="control-sidebar-heading">Tasks Progress</h3>
                <ul class="control-sidebar-menu">
                    <li>
                        <a href="javascript:void(0)">
                            <h4 class="control-sidebar-subheading">
                                Custom Template Design
                                <span class="label label-danger pull-right">70%</span>
                            </h4>

                            <div class="progress progress-xxs">
                                <div class="progress-bar progress-bar-danger" style="width: 70%"></div>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <h4 class="control-sidebar-subheading">
                                Update Resume
                                <span class="label label-success pull-right">95%</span>
                            </h4>

                            <div class="progress progress-xxs">
                                <div class="progress-bar progress-bar-success" style="width: 95%"></div>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <h4 class="control-sidebar-subheading">
                                Laravel Integration
                                <span class="label label-warning pull-right">50%</span>
                            </h4>

                            <div class="progress progress-xxs">
                                <div class="progress-bar progress-bar-warning" style="width: 50%"></div>
                            </div>
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)">
                            <h4 class="control-sidebar-subheading">
                                Back End Framework
                                <span class="label label-primary pull-right">68%</span>
                            </h4>

                            <div class="progress progress-xxs">
                                <div class="progress-bar progress-bar-primary" style="width: 68%"></div>
                            </div>
                        </a>
                    </li>
                </ul>
                <!-- /.control-sidebar-menu -->

            </div>
            <!-- /.tab-pane -->
            <!-- Stats tab content -->
            <div class="tab-pane" id="control-sidebar-stats-tab">Stats Tab Content</div>
            <!-- /.tab-pane -->
            <!-- Settings tab content -->
            <div class="tab-pane" id="control-sidebar-settings-tab">
                <form method="post">
                    <h3 class="control-sidebar-heading">General Settings</h3>

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Report panel usage
                            <input type="checkbox" class="pull-right" checked>
                        </label>

                        <p>
                            Some information about this general settings option
                        </p>
                    </div>
                    <!-- /.form-group -->

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Allow mail redirect
                            <input type="checkbox" class="pull-right" checked>
                        </label>

                        <p>
                            Other sets of options are available
                        </p>
                    </div>
                    <!-- /.form-group -->

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Expose author name in posts
                            <input type="checkbox" class="pull-right" checked>
                        </label>

                        <p>
                            Allow the user to show his name in blog posts
                        </p>
                    </div>
                    <!-- /.form-group -->

                    <h3 class="control-sidebar-heading">Chat Settings</h3>

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Show me as online
                            <input type="checkbox" class="pull-right" checked>
                        </label>
                    </div>
                    <!-- /.form-group -->

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Turn off notifications
                            <input type="checkbox" class="pull-right">
                        </label>
                    </div>
                    <!-- /.form-group -->

                    <div class="form-group">
                        <label class="control-sidebar-subheading">
                            Delete chat history
                            <a href="javascript:void(0)" class="text-red pull-right"><i class="fa fa-trash-o"></i></a>
                        </label>
                    </div>
                    <!-- /.form-group -->
                </form>
            </div>
            <!-- /.tab-pane -->
        </div>
    </aside>
    <!-- /.control-sidebar -->
    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>

    <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel" id="myModal">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="gridSystemModalLabel"></h4>
                </div>
                <div class="modal-body">
                    <table id="twoDisTable" class="table table-bordered table-condensed" cellspacing="0" width="100%">
                        <thead>
                        <tr id="mTh">
                            <th></th>
                        </tr>
                        </thead>
                        <tbody id="myBody">
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="twoDisTableSubmit">提交</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
</div>
<!-- ./wrapper -->

<!-- jQuery 3 -->

<!-- jQuery 3 -->
<script src="../../bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="../../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Select2 -->
<script src="../../bower_components/select2/dist/js/select2.full.min.js"></script>
<!-- InputMask -->
<script src="../../plugins/input-mask/jquery.inputmask.js"></script>
<script src="../../plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="../../plugins/input-mask/jquery.inputmask.extensions.js"></script>
<!-- date-range-picker -->
<script src="../../bower_components/moment/min/moment.min.js"></script>
<script src="../../bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
<!-- bootstrap datepicker -->
<script src="../../bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<!-- bootstrap color picker -->
<script src="../../bower_components/bootstrap-colorpicker/dist/js/bootstrap-colorpicker.min.js"></script>
<!-- bootstrap time picker -->
<script src="../../plugins/timepicker/bootstrap-timepicker.min.js"></script>
<!-- SlimScroll -->
<script src="../../bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- iCheck 1.0.1 -->
<script src="../../plugins/iCheck/icheck.min.js"></script>
<!-- FastClick -->
<script src="../../bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="../../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../dist/js/demo.js"></script>
<!-- DataTables -->
<script src="../../bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="../../bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<!-- Page script -->
<script>
    //商品对应尺寸
    var currentSizes =[];
    //商品对应颜色
    var currentColors = [];
    //二维输入表格
    var twoDisTable;
    //调拨表格
    var mainTable;
    //左边表格
    var leftTable;
    //选中的商品条码
    var selectBarCode;
    //调拨单表单
    var dataForm;

    $(function () {
        //Initialize Select2 Elements
        $('.select2').select2()

        //Datemask dd/mm/yyyy
        $('#datemask').inputmask('dd/mm/yyyy', { 'placeholder': 'dd/mm/yyyy' })
        //Datemask2 mm/dd/yyyy
        $('#datemask2').inputmask('mm/dd/yyyy', { 'placeholder': 'mm/dd/yyyy' })
        //Money Euro
        $('[data-mask]').inputmask()

        //Date range picker
        $('#reservation').daterangepicker()
        //Date range picker with time picker
        $('#reservationtime').daterangepicker({ timePicker: true, timePickerIncrement: 30, format: 'MM/DD/YYYY h:mm A' })
        //Date range as a button
        $('#daterange-btn').daterangepicker(
            {
                ranges   : {
                    'Today'       : [moment(), moment()],
                    'Yesterday'   : [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                    'Last 7 Days' : [moment().subtract(6, 'days'), moment()],
                    'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                    'This Month'  : [moment().startOf('month'), moment().endOf('month')],
                    'Last Month'  : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
                },
                startDate: moment().subtract(29, 'days'),
                endDate  : moment()
            },
            function (start, end) {
                $('#daterange-btn span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'))
            }
        )

        //Date picker
        $('#datepicker').datepicker({
            autoclose: true
        })

        //Timepicker
        $('.timepicker').timepicker({
            showInputs: false
        })
    })

    $(function () {
        $("#leftTable").DataTable({
            "autoWidth": true,
            "searching": true,
            'lengthChange': false,
            "pageLength": 4,
            "columnDefs": [
                {
                    "targets": [ 0 ],
                    "visible": false,
                    "searchable": false
                }]
        });
    });

    $(function(){
        $("#goodsOption").change(function () {
            if(twoDisTable!=null){
                //重置
                twoDisTable.destroy();
                twoDisTable=null;
                $("#mTh th").remove();
                $("#mTh").append("<th></th>")
                $("#myBody tr").remove();
            }
            var barCode = $(this ).val();
            if(!barCode){//判断是否为空{}
                alert("商品条码为空");
                return false;
            }
            //显示商品名字
            var text = $('#goodsOption option:selected').text();
            $("#gridSystemModalLabel").text(text);
            $.ajax({
                type:"GET",
                url:"/requisition_note/getGoodsInfo",
                data: {
                    barCode:barCode
                },
                success:function (response) {
                    var data = response.data;
                    selectBarCode = data.barCode
                    currentSizes = data.sizes;
                    currentColors = data.colors;
                    if(currentSizes.length == 0){
                        alert("商品没有可用的尺码！");
                        return false;
                    }
                    if(currentColors.length == 0){
                        alert("商品没有可用的颜色！");
                        return false;
                    }
                        var sizeThTemp = "";
                        var colorBodyTemp = "";
                        //构建颜色
                        $.each(currentColors,function (index,value) {
                            colorBodyTemp +="<tr><td>"+value.name+"</td>";
                            for (i = 0 ; i<currentSizes.length ; i++ ){
                                //使用中间量 使字符串对象可以有特殊符号如""
                                var temp = "<td><input type= \"number\" style=\"width:100%\" align=\"right\" min='1' name =\"setNumber\"></td>";
                                colorBodyTemp+=temp;
                            }
                            colorBodyTemp+="</tr>";
                        });
                        //构建尺码
                        $.each(currentSizes,function (i,v) {
                            var temp = "<th class=\"text-center\">"+v.name+"</th>";
                            sizeThTemp +=temp
                        });
                        $("#myBody").append(colorBodyTemp);
                        $("#mTh").append(sizeThTemp);

                        //二维输入表格 在Ajax 结束前重置表格
                        twoDisTable = $('#twoDisTable').DataTable({
                            searching: false,
                            bLengthChange: false,
                            paging:false,
                            ordering:  false
                        });
                        //显示二维选择表格
                        $("#myModal").modal('show');
                    }
            })
            return 0;
        })
    })
    //生成调拨单
$(function () {
    $("#twoDisTableSubmit").click(function () {
        var orderDTO;
        var goods = new Array();
        var temp = 0;
        var data = twoDisTable.$("input").toArray();
        for(i = 0 ; i<currentColors.length ; i++){
               var color = currentColors[i];
            for(j = 0 ; j<currentSizes.length;j++){
                var size = currentSizes[j];
                if(data[temp].value !=""){
                    var good = {
                        sizeId : size.id,
                        colorId : color.id,
                        sizeName:size.name,
                        colorName:color.name,
                        goodQuantity : data[temp].value
                    };
                    goods.push(good);
                }
                temp++;

            }
        }
        orderDTO ={
            openid:"fdasdasfsadfsdaurn",
            goodsBarCode:selectBarCode,
            orderDetailList:goods
        }
        if(mainTable!=null){
            //重置
            mainTable.destroy();
            mainTable=null;
        }
        mainTable = $('#mainTable').DataTable({
            'paging'      : true,
            'lengthChange': false,
            'searching'   : true,
            'ordering'    : true,
            'info'        : true,
            'autoWidth'   : false,
            "scrollY": 200,
            "scrollX": true,
             ajax:{
                "url":"/requisition_note/createNote",
                "type":"post",
                "contentType" : "application/json",
                "data":  function () {
                    return JSON.stringify( orderDTO );
                },
                "dataType":"json",
                "dataSrc":function (result) {
                    if(result.msg=="success"){
                        alert("成功生成调拨单在表格中,没有库存的已经发送信息给指定账户进行补货,请确定。" +
                            "如果表格没有商品说明选择调拨的商品都没有仓库可以调拨。")
                        $("#myModal").modal('hide');
                        dataForm = result.data.valueOf();
                        return result.data;
                    }else {
                        alert(result.msg);
                        window.location.reload();
                    }
                }
            },
            "columns": [
                { "data": "orderMaster.goodsName" },
                { "data": "orderDetail.goodId" },
                { "data": "orderMaster.goodsBarCode" },
                { "data": "orderDetail.colorName" },
                { "data": "orderDetail.sizeName"},
                { "data": "orderDetail.goodQuantity"},
                { "data": "orderDetail.goodPrice"},
                { "data": "orderMaster.OrderAmount"}
            ]
        });
       return 0;
    });
})
$("#submitForm").click(function () {
    if(dataForm.length != 0){
        $.ajax({
            url:"/requisition_note/submitForm",
            type:"POST",
            contentType :"application/json",
            data :JSON.stringify( dataForm ),
            dataType:"json",
            success:function (result) {
                if(result.code==1){
                    alert("已经申请调拨和进行补货");
                    window.location.reload();
                }else {
                    alert(result.msg);
                }
            },

        })
    }else {
        alert("无可以保存的商品单");
    }
})
    $("#submitDraft").click(function () {
        if(dataForm.length != 0){
            $.ajax({
                url:"/requisition_note/draft",
                type:"POST",
                contentType :"application/json",
                data :JSON.stringify( dataForm ),
                dataType:"json",
                success:function (result) {
                    if(result.code==1){
                        alert("已经存入草稿");
                        window.location.reload();
                    }else {
                        alert(result.msg);
                    }
                },

            })
        }else {
            alert("无可以保存的商品单");
        }
    })
    //确认调拨完成
    $("#finish").click(function () {
        var orderId = $("#orderIdH").html();
            $.ajax({
                url:"/requisition_note/finish",
                type:"POST",
                data :{
                    "orderId" : orderId
                },
                dataType:"json",
                success:function (result) {
                    if(result.code==1){
                        alert("确认成功！");
                        window.location.reload();
                    }else {
                        alert(result.msg);
                    }
                },
            })
        })
    //确定要进行调拨 确定调拨->正在调拨
    $("#determine").click(function () {
        var orderId = $("#orderIdH").html();
        $.ajax({
            url:"/requisition_note/determine",
            type:"POST",
            data :{
                "orderId" : orderId,
                "remarks":$("#remarks").val()
            },
            dataType:"json",
            success:function (result) {
                if(result.code==1){
                    alert("确认成功！");
                    window.location.reload();
                }else {
                    alert(result.msg);
                }
            },
        })
    })

    //取消调拨请求
    $("#close").click(function () {
        var orderId = $("#orderIdH").html();
        $.ajax({
            url:"/requisition_note/close",
            type:"POST",
            data :{
                "orderId" : orderId
            },
            dataType:"json",
            success:function (result) {
                if(result.code==1){
                    alert("确认取消成功！");
                    window.location.reload();
                }else {
                    alert(result.msg);
                }
            },
        })
    })


    //点击表格触发触发事件请选择你要调拨的商品
    $('#leftTable tbody').on('click', 'tr', function () {
        var table = $('#leftTable').DataTable();
        var data = table.row( this ).data();
        $("#remarks").attr("disabled","disabled");
        $("#goodsSelectD").hide();
        hideAllButtons();
        var status =$(data[4]);
        switch (status.html()) {
            case "草稿":
                $("#submitDraft").show();
                break;
            case "等待确认":
                $("#close").show();
                $("#determine").show();
                $("#remarks").removeAttr("disabled");
                break;
            case "正在调拨":
                $("#finish").show();
                $("#close").show();
                break;
        }

        var orderId = data[0];
        $("#orderIdH").html(orderId);
        $("#outStore").val(data[1]);
        $("#inStore").val(data[2]);
        $("#time").val(data[3]);
        $("#remarksD").show();
        if(mainTable!=null){
            //重置
            mainTable.destroy();
            mainTable=null;
        }
        mainTable = $('#mainTable').DataTable({
            'paging'      : true,
            'lengthChange': false,
            'searching'   : true,
            'ordering'    : true,
            'info'        : true,
            'autoWidth'   : false,
            "scrollY": 200,
            "scrollX": true,
            ajax:{
                "url":"/requisition_note/getOneOrder",
                "type":"post",
                "data": {
                    orderId: orderId
                },
                "dataType":"json",
                "dataSrc":function (result) {
                    if(result.msg=="success"){
                        var data = result.data;;
                        $("#remarks").val(data[0].orderMaster.remarks);
                        return data;
                    }else {
                        alert(result.msg);
                        window.location.reload();
                    }
                }
            },
            "columns": [
                { "data": "orderMaster.goodsName" },
                { "data": "orderDetail.goodId" },
                { "data": "orderMaster.goodsBarCode" },
                { "data": "orderDetail.colorName" },
                { "data": "orderDetail.sizeName"},
                { "data": "orderDetail.goodQuantity"},
                { "data": "orderDetail.goodPrice"},
                { "data": "orderMaster.orderAmount"}
            ]
        });
    } );

    $("#addRequisition").click(function () {
        if(mainTable!=null){
            //重置
            mainTable.clear();
            mainTable.destroy();
            mainTable=null;
        }
        $("#remarks").attr("disabled","disabled");
        hideAllButtons();
        $("#submitDraft").show();
        $("#submitForm").show();
        $("#orderIdH").html("");
        $("#outStore").val("");
        $("#inStore").val("");
        $("#time").val("");
        $("#goodsSelectD").show();
    })
    function hideAllButtons() {
        $("#submitDraft").hide();
        $("#submitForm").hide();
        $("#finish").hide();
        $("#determine").hide();
        $("#close").hide();
    }
</script>

</body>
</html>
